package org.icosagon.core;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import org.icosagon.core.MetaData;

/**
 *
 * @author Daniel Owens
 */
public class Definable {
    private String name = null;
    private String description = null;
    private MetaData meta = null;
    private int id = -1;

    public MetaData getMetaData() {
        return meta;
    }

    public void setMetaData(MetaData meta) {
        this.meta = meta;
    }

    public void setName(String name) {
        name = name.trim();
        if(name == null)
            name = "";
        this.name = name;
    }

    @XmlAttribute
    public String getName() {
        return this.name;
    }

    public void setDescription(String desc) {
        this.description = desc.trim();
    }

    @XmlElement(required=false)
    public String getDescription() {
        return this.description;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int value) {
        this.id = value;
    }

    @Override public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Definable other = (Definable) obj;
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if (this.meta != other.meta && (this.meta == null || !this.meta.equals(other.meta))) {
            return false;
        }
        return true;
    }

    @Override public int hashCode() {
        return this.name.hashCode()+(meta.getCreator().toLowerCase()).hashCode()+(meta.getName().toLowerCase()).hashCode();
    }
}